<template>
  <el-dialog :close-on-click-modal='false' v-drag :title="$t('升级')" :v-if="dialogVisible" :visible.sync="dialogVisible" width="700px" top="5%" @close='close'>
    <el-table size='mini' ref="multipleTable" :data="updateInfo" tooltip-effect="dark">
      <el-table-column prop="name" align='center' :label="$t('名称')" min-width="200"></el-table-column>
      <el-table-column prop="date" align='center' :label="$t('更新时间')" min-width="200"></el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button type="success" @click="upgrade" class="updata">{{$t('升级')}}</el-button>
      <el-button type="danger" @click="deleteFile" class="del">{{$t('删除')}}</el-button>
      <el-button @click="close" class="addClose">{{$t('取 消')}}</el-button>
    </span>
  </el-dialog>
</template>
<script>

import { getUpgrade, getFirmwareInfo, delFirmwareInfo } from '@/api/system/update'
export default {
  name: 'uploadFile',
  data () {
    return {
      dialogVisible: false,
      updateInfo: [],
      fileList: []
    }
  },
  methods: {
    init () {
      this.dialogVisible = true
      getFirmwareInfo().then(res => {
        if (res.status === 0) {
          this.updateInfo = res.info[0].package
        }
      })
    },
    handleSelectionChange (data) {
      this.fileList = data
    },
    upgrade () {
      getUpgrade({ name: this.updateInfo[0].name }).then(res => {
        if (res.status === 0) {
          this.$message({
            message: this.$t('升级成功'),
            type: 'success'
          })
          this.$parent.listData()
          this.close()
        }
      })
      // this.$parent.listData()
      // this.close()
    },
    deleteFile () {
      delFirmwareInfo({ name: this.updateInfo[0].name }).then(res => {
        if (res.status === 0) {
          this.$message({
            message: this.$t('删除成功'),
            type: 'success'
          })
          this.$parent.listData()
          this.close()
        }
      })
    },
    close () {
      this.updateInfo = []
      this.dialogVisible = false
    }
  }
}
</script>
